Skip to content

[chain] Apply exported lint rule#2018

Closed
RodrigoVillar wants to merge 11 commits intomainfrom
chain-export
Closed

[chain] Apply exported lint rule#2018
RodrigoVillar wants to merge 11 commits intomainfrom
chain-export

Conversation

@RodrigoVillar
Copy link
Copy Markdown
Contributor

@RodrigoVillar RodrigoVillar commented Apr 8, 2025

This PR applies the exported lint rule to the chain package, which forces documentation on exported functions and interfaces.

Long term, we will want to apply exported to all public facing packages, but this is a good starting point.

@RodrigoVillar RodrigoVillar added the documentation Improvements or additions to documentation label Apr 8, 2025
@RodrigoVillar RodrigoVillar self-assigned this Apr 8, 2025
Comment thread .golangci.yml Outdated
Comment on lines +198 to +228
exclude:
- "**/abi/**/*.go"
- "**/api/**/*.go"
- "**/auth/**/*.go"
- "**/chainindexer/**/*.go"
- "**/cli/**/*.go"
- "**/cmd/**/*.go"
- "**/codec/**/*.go"
- "**/consts/**/*.go"
- "**/context/**/*.go"
- "**/crypto/**/*.go"
- "**/event/**/*.go"
- "**/examples/**/*.go"
- "**/extension/**/*.go"
- "**/fees/**/*.go"
- "**/genesis/**/*.go"
- "**/internal/**/*.go"
- "**/keys/**/*.go"
- "**/proto/**/*.go"
- "**/pubsub/**/*.go"
- "**/requester/**/*.go"
- "**/snow/**/*.go"
- "**/state/**/*.go"
- "**/statesync/**/*.go"
- "**/storage/**/*.go"
- "**/tests/**/*.go"
- "**/throughput/**/*.go"
- "**/utils/**/*.go"
- "**/vm/**/*.go"
- "**/x/**/*.go"
- "TEST"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, a regex that includes all packages except chain would've been better here. However, since we plan on applying the exported rule to all public-facing packages, it might be better to leave it in this format.

@RodrigoVillar RodrigoVillar changed the title [chain] Apply export lint rule [chain] Apply exported lint rule Apr 9, 2025
@RodrigoVillar RodrigoVillar marked this pull request as ready for review April 9, 2025 14:09
@RodrigoVillar RodrigoVillar requested a review from Elvis339 April 9, 2025 14:09
Copy link
Copy Markdown
Contributor

@Elvis339 Elvis339 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why isn't exported rule picking up on this... Will play a bit and see what I find out.

Comment thread .golangci.yml Outdated
Comment thread chain/dependencies.go
Len(context.Context) int // items
Size(context.Context) int // bytes
// Number of items
Len(context.Context) int
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter doesn't seem to apply exported rule correctly.

The Go documentation guidelines specify that documentation comments for exported identifiers should start with the name being declared. This helps with generated documentation, maintains a consistent style, and makes it clear what's being described, especially when multiple declarations are being documented in sequence.

// This lacks a comment
func HandleRequest(w http.ResponseWriter, r *http.Request) {
    // ...
}

// Processes incoming HTTP requests
func HandleRequest(w http.ResponseWriter, r *http.Request) {
    // ...
}

Both of these functions should be targeted.
GoLand IDE is reporting invalid comment pattern as well.

Screenshot 2025-04-09 at 6 27 37 PM

@RodrigoVillar
Copy link
Copy Markdown
Contributor Author

RodrigoVillar commented Apr 9, 2025

Putting this back into draft; realized that revive isn't being enforced in its entirety by our linter due to exclusion-presets

@RodrigoVillar RodrigoVillar marked this pull request as draft April 9, 2025 16:23
RodrigoVillar and others added 2 commits April 9, 2025 12:38
Co-authored-by: Elvis <43846394+Elvis339@users.noreply.github.com>
Signed-off-by: rodrigo <77309055+RodrigoVillar@users.noreply.github.com>
Comment thread .golangci.yml Outdated
Comment on lines +26 to +42
exclude:
- 'Error return value of
.((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv).
is not checked'
- '(comment on exported (method|function|type|const)|should have( a
package)? comment|comment should be of the form)'
- 'func name will be used as test\.Test.* by other packages, and that
stutters; consider calling this'
- '(possible misuse of unsafe.Pointer|should have signature)'
- 'SA4011'
- 'G103: Use of unsafe calls should be audited'
- 'G204: Subprocess launched with variable'
- 'G104'
- '(G301|G302|G307): Expect (directory permissions to be 0750|file
permissions to be 0600) or less'
- 'G304: Potential file inclusion via variable'
- '(ST1000|ST1020|ST1021|ST1022)'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Elvis339 these are the list of regex exclusions that were previously enforced by exclude-use-defaults, but now have to be manually excluded.

To see the full list of default regex exclusions (including the revive ones we're now enforcing), you can query via golangci-lint run --help and scroll to the --exclude-use-default flag

@RodrigoVillar
Copy link
Copy Markdown
Contributor Author

https://github.com/ava-labs/hypersdk/actions/runs/14362530871/job/40267461117?pr=2018#step:4:1201 ❤️

@RodrigoVillar
Copy link
Copy Markdown
Contributor Author

Closing this in favor in a future PR which targets a smaller package. The goal of this PR was to commit to eventually adding documentation for all PRs (via revive/staticcheck) but its clear that choosing the chain package was not ideal due to its size.

A future PR should target the context package, since its much smaller in scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants